<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>出库单</title>
    <% include("../layout/css.html"){} %>
</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card card-box-shadow">
    	<div class="layui-card-body">
	        <div class="layui-form toolbar">
	            <div class="layui-form-item">
	                <div class="layui-inline">
	                    <label class="layui-form-label w-auto">搜索：</label>
                        <div class="layui-input-inline mr0">
                            <input name="keywords" class="layui-input" type="text" placeholder="出库单号,供应商"/>
                        </div>
	                </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">出库日期：</label>
                        <div class="layui-input-inline mr0">
                            <input id="date1" name="date1" class="layui-input"
                                   type="text" placeholder="开始时间" autocomplete="off"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">到</label>
                        <div class="layui-input-inline mr0">
                            <input id="date2" name="date2" class="layui-input"
                                   type="text" placeholder="结束时间" autocomplete="off"/>
                        </div>
                    </div>
	                <div class="layui-inline">
	                    <button class="layui-btn icon-btn" lay-filter="searchSubmit" lay-submit>
	                        <i class="layui-icon">&#xe615;</i>搜索
	                    </button>
	                    <% if(so.hasPermission("outBill:add")){ %>
	                    <button id="btnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
	                    <% } %>
	                </div>
	            </div>
	        </div>
        	<table class="layui-table" id="outBillTable" lay-filter="outBillTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBar">
	<% if(so.hasPermission("outBill:update")){ %>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <% } %>
    <!--<% if(so.hasPermission("outBill:delete")){ %>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <% } %>-->
</script>
<!-- 表单弹窗 -->
<script type="text/html" id="modelOutBill">
    <form id="modelOutBillForm" lay-filter="modelOutBillForm" class="layui-form model-form">
        <input name="id" id="id" type="hidden"/>
        <input name="companyId" type="hidden"/>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label">出库单号</label>
                <div class="layui-input-block">
                   <input id="code" name="code"  type="text" class="layui-input"  autocomplete="off"
                   lay-verType="tips" lay-verify="" placeholder="请输入出库单号"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">供应商</label>
                <div class="layui-input-block">
                   <input id="supplier" name="supplier"  type="text" class="layui-input"  autocomplete="off"
                   lay-verType="tips" lay-verify="" placeholder="请输入供应商"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">出库日期</label>
                <div class="layui-input-block">
                   <input id="outTime" name="outTime"  type="text" class="layui-input"  autocomplete="off"
                   lay-verType="tips" lay-verify="" placeholder="请输入出库日期"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label">仓库</label>
                <div class="layui-input-block">
                   <input id="warehouseName" name="warehouseName"  type="text" class="layui-input"  autocomplete="off"
                   lay-verType="tips" lay-verify="" placeholder="请输入仓库"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                   <input id="remark" name="remark"  type="text" class="layui-input"  autocomplete="off"
                   lay-verType="tips" lay-verify="" placeholder="请输入备注"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closePageDialog">取消</button>
            <button class="layui-btn" lay-filter="modelOutBillSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- js部分 -->
<% include("../layout/js.html"){} %>
<script type="text/javascript">
    layui.use(['layer', 'form', 'formX', 'index','table', 'util', 'admin', 'zTree', 'tableX','laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var tableX = layui.tableX;
        var formX = layui.formX;
        var index = layui.index;
        var laydate = layui.laydate;

        //日期时间选择器
        laydate.render({
            elem: '#date1'
            ,type: 'date'
        });
        laydate.render({
            elem: '#date2'
            ,type: 'date'
        });

        // 渲染表格
        var insTb = tableX.render({
            elem: '#outBillTable'
            ,url: 'outBill/list'
            ,page: true
            ,toolbar: true
            ,cellMinWidth: 100
            ,cols: [[
                {type: 'numbers'}
                ,{field: "code", minWidth: "60", title: "出库单号", sort: true, hide:false }
                ,{field: "supplier", minWidth: "60", title: "供应商", sort: true, hide:false }
                ,{field: "outTime", minWidth: "60", title: "出库日期", sort: true, hide:false }
                ,{field: "warehouseName", minWidth: "60", title: "仓库", sort: true, hide:false }
                ,{field: "remark", minWidth: "60", title: "备注", sort: true, hide:true }
                ,{field: "createTime", minWidth: "60", title: "创建时间", sort: true, hide:true ,templet: function (d) {
                        return util.toDateString(d.createTime);
                    }
                }
                ,{field: "createUser", minWidth: "60", title: "创建人", sort: true, hide:true }
                ,{field: "updateTime", minWidth: "60", title: "更新时间", sort: true, hide:true ,templet: function (d) {
                        return util.toDateString(d.createTime);
                    }
                }
                ,{field: "updateUser", minWidth: "60", title: "更新人", sort: true, hide:true }
                ,{align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 200}
            ]]
        });

        // 添加
        $('#btnAdd').click(function () {
            showEditModel();
        });

        // 搜索
        form.on('submit(searchSubmit)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}});
        });

        // 工具条点击事件
        table.on('tool(outBillTable)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 修改
                showEditModel(data);
            } else if (layEvent === 'del') { // 删除
                doDel(obj);
            }
        });

        // 删除
        function doDel(obj) {
            layer.confirm('确定要删除“' + obj.data.name + '”出库单吗？', {
                shade: .1,
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                $.post('outBill/delete', {
                    ids: obj.data.id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload();
                        top.productStorageTableReload();
                        //obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'json');
            });
        }

        // 显示编辑弹窗
        function showEditModel(mOutBill) {
            index.openTab({
                title: (mOutBill ? '修改' : '添加') + '出库单',
                url: 'sell/outBillSon?id='+(mOutBill!=undefined ? mOutBill.id : ""),
                end: function() {
                    // table.reload('userTable');
                }
            });
            /*admin.open({
                type: 1,
                maxmin:true,
                closeBtn:1,
                resize: true,
                area:["900px","500px"],
                title: (mOutBill ? '修改' : '添加') + '出库单',
                content: $('#modelOutBill').html(),
                success: function (layero, dIndex) {
                    var url = mOutBill ? 'outBill/update' : 'outBill/add';
                    form.val('modelOutBillForm', mOutBill);  // 回显数据
                    // 表单提交事件
                    form.on('submit(modelOutBillSubmit)', function (data) {
                        layer.load(2);
                        $.post(url, data.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload();
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'json');
						$("button[lay-filter='modelOutBillSubmit']").attr("disabled","disabled");
                        setTimeout(function(){$("button[lay-filter='modelOutBillSubmit']").removeAttr("disabled");}, 1000 );
                        return false;
                    });
					laydate.render({
					    elem: '#outTime'
					    ,type: 'datetime'
					});

                }
            });*/
        }
        top.outBillTable = function(){
            insTb.reload();
        }
    });
</script>
</body>
</html>
